<!--
 * @Descripttion: 
 * @version: 
 * @Author: ada.wu
 * @Date: 2023-10-29 20:56:13
 * @LastEditors: ada.wu
 * @LastEditTime: 2023-11-26 20:15:50
-->
<template>
  <div>
    <div class="app_card pt-4  pb-5">
      <el-table v-loading="loading" element-loading-text="查询中..." stripe size="large" :data="dataOfTable"
        height="calc(100vh - 240px)">
        <el-table-column label="卡号" prop="cardNo" align="center">
          <template #default="scope">{{ scope.row.cardNo }}</template>
        </el-table-column>
        <el-table-column label="工/学号" prop="jobNumber" align="center">
          <template #default="scope">{{ scope.row.jobNumber }}</template>
        </el-table-column>
        <el-table-column label="姓名" prop="name" align="center">
          <template #default="scope">{{ scope.row.name }}</template>
        </el-table-column>
        <el-table-column label="学院" prop="college" align="center">
          <template #default="scope">{{ scope.row.college }}</template>
        </el-table-column>
        <el-table-column label="类型" prop="result" align="center">
          <template #default="scope">
            <el-tag :type="scope.row.result == 0 ? 'success' : 'danger'">{{
              scope.row.result == 0 ? "成功" : "失败"
            }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="教室" prop="roomName" align="center">
          <template #default="scope">{{ scope.row.roomName }}</template>
        </el-table-column>
        <el-table-column label="时间" prop="actionTime" align="center">
          <template #default="scope">{{ resetForm('YYYY-mm-dd HH:MM:SS', scope.row.actionTime) }}</template>
        </el-table-column>
      </el-table>
      <Pagination ref="paginationRef" @handleChange="handleChange" />
    </div>
  </div>
</template>
<script setup>
/**
 * 刷卡日志
 */
import { ref, onMounted } from 'vue';
import { ElMessageBox, ElMessage } from 'element-plus';
import EsAjax from '@/utils/EsAjax';
import ApiUrls from '@/apis/index';
import Pagination from '@/components/pagination/index.vue';
import { resetForm } from '@/utils/EsDate.js';

//组件

// ======================================================
//                      变量声明
// ======================================================
const loading = ref(false);
// 表格数据
const dataOfTable = ref([]);
// 表格查询参数
const queryParam = ref({
  sort: "id",
  order: "desc",
  limit: 10,
  page: 1,
})
// 组件引用
const paginationRef = ref(null);
// ======================================================
//                      处理事件
// ======================================================
// 处理分页尺寸
const handleChange = (data = null) => {
  queryParam.value.page = data?.page;
  queryParam.value.limit = data?.limit;
  loadData();
}
// ======================================================
//                      处理事件
// ======================================================
const loadData = () => {
  let _queryParam = queryParam.value
  _queryParam.offset = (_queryParam.page - 1) * _queryParam.limit || 0;
  loading.value = true
  EsAjax.post(ApiUrls.logCard, { ..._queryParam }).then(res => {
    if (res.data.code != 200) {
      ElMessage.warning(res.data.data + res.data.msg);
      return;
    }
    let { list, totalCount } = res.data.data
    dataOfTable.value = list;
    paginationRef.value?.changeTotal({ totalCount: totalCount })
  }).catch(err => {
    ElMessage.error(err.message);
  }).finally(() => {
    loading.value = false
  })
}


onMounted(() => {
  loadData();
})

</script>
